#ifndef W_BATTERY_H
#define W_BATTERY_H

#include<QWidget>

/**
  * 自定义电池控件
  */
#ifdef quc
class Q_DECL_EXPORT W_Battery : public QWidget
#else
class W_Battery: public QWidget
#endif
{
    Q_OBJECT

    Q_PROPERTY(double minValue READ getMinValue WRITE setMinValue)
    Q_PROPERTY(double maxValue READ getMaxValue WRITE setMaxValue)
    Q_PROPERTY(double value READ getValue WRITE setValue)
    Q_PROPERTY(double alarmValue READ getAlarmValue WRITE setAlarmValue)

    Q_PROPERTY(double step READ getStep WRITE setStep)
    Q_PROPERTY(int borderWidth READ getBorderWidth WRITE setBorderWidth)
    Q_PROPERTY(int borderRadius READ getBorderRadius WRITE setBorderRadius)
    Q_PROPERTY(int bgRadius READ getBgRadius WRITE setBgRadius)
    Q_PROPERTY(int headRadius READ getHeadRadius WRITE setHeadRadius)

    Q_PROPERTY(QColor borderColorStart READ getBorderColorStart WRITE setBorderColorStart)
    Q_PROPERTY(QColor borderColorEnd READ getBorderColorEnd WRITE setBorderColorEnd)

    Q_PROPERTY(QColor alarmColorStart READ getAlarmColorStart WRITE setAlarmColorStart)
    Q_PROPERTY(QColor alarmColorEnd READ getAlarmColorEnd WRITE setAlarmColorEnd)

    Q_PROPERTY(QColor normalColorStart READ getNormalColorStart WRITE setNormalColorStart)
    Q_PROPERTY(QColor normalColorEnd READ getNormalColorEnd WRITE setNormalColorEnd)

public:
    explicit W_Battery(QWidget *parent = 0); //构造函数被explicit修饰后, 就不能再被隐式调用了.
    ~W_Battery();

protected:
    void paintEvent(QPaintEvent *);
    void drawBorder(QPainter *painter);
    void drawBg(QPainter *painter);
    void drawHead(QPainter *painter);

private slots:
    void updateValue();

private:
    double minValue;
    double maxValue;
    double value;
    double alarmValue;

    double step;
    int borderWidth;
    int borderRadius;
    int bgRadius;
    int headRadius;

    QColor borderColorStart;
    QColor borderColorEnd;

    QColor alarmColorStart;
    QColor alarmColorEnd;

    QColor normalColorStart;
    QColor normalColorEnd;

    bool isForward;
    double currentValue;
    QRectF batteryRect;
    QTimer *timer;

public:
    double getMinValue() const;
    double getMaxValue() const;
    double getValue()    const;
    double getAlarmValue() const;

    double getStep() const;
    int getBorderWidth() const;
    int getBorderRadius() const;
    int getBgRadius() const;
    int getHeadRadius() const;

    QColor getBorderColorStart() const;
    QColor getBorderColorEnd() const;

    QColor getAlarmColorStart() const;
    QColor getAlarmColorEnd() const;

    QColor getNormalColorStart() const;
    QColor getNormalColorEnd() const;

    QSize sizeHint() const;
    QSize mininumSizeHint() const;

public Q_SLOTS:
    //
    void setRange(double minValue, double maxValue);
    void setRange(int minValue, int maxValue);

    void setMinValue(double minValue);
    void setMaxValue(double maxValue);

    void setValue(double value);
    void setValue(int value);

    void setAlarmValue(double alarmValue);
    void setAlarmValue(int alarmValue);

    void setStep(double step);
    void setStep(int step);

    void setBorderWidth(int borderWidth);
    void setBorderRadius(int borderRadius);
    void setBgRadius(int bgRadius);
    void setHeadRadius(int headRadius);

    void setBorderColorStart(const QColor &borderColorStart);
    void setBorderColorEnd(const QColor &borderColorEnd);

    void setAlarmColorStart(const QColor &alaramColorStart);
    void setAlarmColorEnd(const QColor &alaramColorEnd);

    void setNormalColorStart(const QColor &normalColorStart);
    void setNormalColorEnd(const QColor &normalColorEnd);

Q_SIGNALS:
    void valueChanged(double value);

};

#endif // W_BATTERY_H
